from django.db import models
from app.user.models import McUser
from app.gender.models import McGender
from app.identity.models import McIdentity


class McPatient(models.Model):
    # 关键：设为外键，并指定使用同名列
    user = models.ForeignKey(
        McUser,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        db_column="user_id",
    )

    name = models.CharField(max_length=50, null=True, blank=True)
    identity = models.ForeignKey(
        McIdentity,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        db_column="identity_id",
  
    )
    identity_number = models.CharField(max_length=100)
    gender = models.ForeignKey(
        McGender,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        db_column="gender_id",
    )
    age = models.PositiveIntegerField()
    phone = models.BigIntegerField()
    relation = models.CharField(max_length=50, null=True, blank=True)
    created_time = models.DateTimeField(auto_now_add=True)
    updated_time = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'mc_patient'
        verbose_name = '就诊人'
        verbose_name_plural = '就诊人'